Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automation] Add support for synchronized execution of compiled scripts #4402

Merged
merged 4 commits into from
Oct 6, 2024

Conversation

florian-h05
Copy link
Contributor

If the ScriptEngine implements the Lock interface, the execution of the CompiledScript is synced by acquisition and release of the log.
This is required for add-ons like JS Scripting.

…e implements Lock interface

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 requested a review from a team as a code owner October 4, 2024 23:22
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 marked this pull request as draft October 4, 2024 23:47
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 requested a review from J-N-K October 5, 2024 09:27
@florian-h05
Copy link
Contributor Author

@J-N-K I adressed your review 👍

@florian-h05 florian-h05 marked this pull request as ready for review October 5, 2024 09:28
@florian-h05 florian-h05 changed the title [automation] Synchronize execution of compiled scripts if needed [automation] Add support for synchronized execution of compiled scripts Oct 5, 2024
@florian-h05
Copy link
Contributor Author

FYI this is for openhab/openhab-addons#17510.

@florian-h05
Copy link
Contributor Author

Jenkins finally finished the PR build.

Comment on lines 214 to 223
return compiledScript.get().eval(engine.getContext());
Object result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you create a new object here? You could also return it directly and move the return null from the ScriptException catch-block to the end of method (or return nul in the finally block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It "feels" better this way for me when reading the code, but I have changed it.

Comment on lines 215 to 216
if (engine instanceof Lock lock) {
if (!lock.tryLock(1, TimeUnit.MINUTES)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (engine instanceof Lock lock) {
if (!lock.tryLock(1, TimeUnit.MINUTES)) {
if (engine instanceof Lock lock && !lock.tryLock(1, TimeUnit.MINUTES)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 requested a review from J-N-K October 6, 2024 14:17
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@J-N-K J-N-K merged commit d012d36 into openhab:main Oct 6, 2024
5 checks passed
@J-N-K J-N-K added the enhancement An enhancement or new feature of the Core label Oct 6, 2024
@J-N-K J-N-K added this to the 4.3 milestone Oct 6, 2024
@florian-h05 florian-h05 deleted the precompiled-script-synchronization branch October 6, 2024 17:47
florian-h05 added a commit to florian-h05/openhab-core that referenced this pull request Oct 26, 2024
…implements Lock

This moves the locking mechanism added in openhab#4402 to the inheritors of AbstractScriptModuleHandler
to synchronize execution context access as well.

This fixes the problem thathttps://github.com/openhab/openhab-addons/pull/17510 worked around by using Thread.sleep.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
kaikreuzer pushed a commit that referenced this pull request Oct 26, 2024
…implements Lock (#4426)

This moves the locking mechanism added in #4402 to the inheritors of AbstractScriptModuleHandler
to synchronize execution context access as well.

This fixes the problem thathttps://github.com/openhab/openhab-addons/pull/17510 worked around by using Thread.sleep.

Signed-off-by: Florian Hotze <dev@florianhotze.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants